﻿public class RoleAttr
{
    public long roleID;
    public string roleName;     //角色名
    public long gold;           //金币
    public long diamond;        //钻石
    public long chaCoin;        //挑战币
    public long exp;            //经验
    public long vipExp;         //vip经验
    public int vipLv;           //VIP等级
    public int power;           //体力值
    public int level;           //等级

    public void Clear()
    {
        roleID = -1;
        roleName = "";
        gold = -1;
        vipExp = -1;
        diamond = -1;
        chaCoin = -1;
        exp = -1;
        level = 0;
        vipLv = 0;
        power = 0;
    }
}

public class PlayerData : Singleton<PlayerData>, IBaseData
{
    /////////// 字段和属性 ///////////////////
    public string userName;                 //用户名
    public string loginToken;               //登录Token
    public EPLATFORM platForm;              //渠道标识

    public RoleAttr roleAttr;

    /// <summary>
    /// 数据是否初始化
    /// </summary>
    public bool isInit;
    /// <summary>
    /// //网关主机
    /// </summary>
    public string gateHost = "127.0.0.1";   
    
    public PlayerData()
    {
        roleAttr = new RoleAttr();
    }

    public void Init() { }

    /// <summary>
    /// 重新登录，断线重连 初始化数据
    /// </summary>
    public void ReconnectInitData()
    {
        // 清空计时器
        ZMgr.TimerMgr.ClearAllTimeOut();
        // 清空新手引导信息
        ZMgr.GuideMgr.StopGuide();
        // 清空资源加载信息
        ZMgr.SceneMgr.isInit = false;
        ZMgr.SceneMgr.isloading = false;
        GetSingleton().isInit = false;
    }
    
    public bool IsMoneyEnough(EItemID moneyType, long num, bool bIsTips = true)
    {
        if (moneyType == EItemID.Gold)
        {
            if (roleAttr.gold < num)
            {
                if (bIsTips)
                {
                    //错误码提示
                }
                return false;
            }

        }
        else if (moneyType == EItemID.Diamond)
        {
            if (roleAttr.diamond < num)
            {
                if (bIsTips)
                {
                    //错误码提示
                }
                return false;
            }
        }
        return true;
    }
}